﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.Manage.SqlServerDAL;

public partial class Common_OrgPersTree : System.Web.UI.Page
{
    int iPersCount = 0;
   // private string rightType = "1"; //权限类别 1 表示档案工资，0表示活动工资。



    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack == false)
        {
            try
            {
                HPageID.Value = Request["ChoiceID"].ToString().Trim();
            }
            catch
            {
                HPageID.Value = "0";
            }

            try
            {
                HOrgType.Value = Request["OrgType"].ToString().Trim();
            }
            catch
            {
                HOrgType.Value = "0";
            }

           
            #region 加载机构信息
            DataTable dtOrgs = SysOrgDAL.GetSysOrgOtherInfosByOrgIds( AspNetHelper .GetRightOrgIds());

            if (dtOrgs == null) return;

            TreeNode rootNode;
            //获取根节点


            foreach (DataRow dr in dtOrgs.Rows)
            {

                rootNode = new TreeNode();
                rootNode.Value = dr["ID"].ToString();
                // <INPUT type='checkbox' id='chkPlan' value='"+drv["ID"].ToString()+"' onclick='searchArea(this);'>
                rootNode.Text = dr["Name"].ToString();
                rootNode.ImageUrl = "~/PayManage/XmlTree/icon/close.gif";
                //rootNode.SelectAction = TreeNodeSelectAction;
                //rootNode.PopulateOnDemand = true;
                //rootNode.NavigateUrl = function.Url;
                this.tvOrgTree.Nodes.Add(rootNode);
                //rootNode.Expand();

            }
            #endregion

            #region 加载人员信息
            DataTable dtEmps = SysOrgDAL.GetSysPersInfosByDeptId(0);
            if (dtEmps == null) return;
            //获取根节点


            foreach (DataRow dr in dtEmps.Rows)
            {
                iPersCount += 1;
                PersCount.Value = Convert.ToString(iPersCount);
                rootNode = new TreeNode();
                rootNode.Value = dr["ID"].ToString();
                rootNode.Text = "<INPUT type='checkbox' id='PersCK' name='PersCK' value='" + dr["ID"].ToString() + "," + dr["Name"].ToString() + "'  onclick='ChoicePer(this);' >" + dr["Name"].ToString();
                rootNode.ImageUrl = "~/PayManage/XmlTree/icon/file2.gif";
                //rootNode.SelectAction = TreeNodeSelectAction;
                //rootNode.PopulateOnDemand = true;
                //rootNode.NavigateUrl = "../PayManage/EmpCom_File_Edit.aspx?ID=" + dr["ID"].ToString() + parmStr;
                this.tvOrgTree.Nodes.Add(rootNode);
                //rootNode.Expand();

            }
            #endregion
        }
    }
    protected void tvOrgTree_SelectedNodeChanged(object sender, EventArgs e)
    {
        if (this.tvOrgTree.SelectedNode == null || this.tvOrgTree.SelectedNode.ChildNodes.Count > 0 || this.tvOrgTree.SelectedNode.NavigateUrl != string.Empty) return;

        int orgId = int.Parse(this.tvOrgTree.SelectedNode.Value);
        #region 加载机构信息
        DataTable dt = SysOrgDAL.GetSysOrgOtherInfosByParentId(orgId);

        TreeNode rootNode;
        //获取根节点


        foreach (DataRow dr in dt.Rows)
        {

            rootNode = new TreeNode();
            rootNode.Value = dr["ID"].ToString();
            rootNode.Text =  dr["Name"].ToString();
            rootNode.ImageUrl = "~/PayManage/XmlTree/icon/close.gif";
            //rootNode.ImageToolTip = "";
            //rootNode.PopulateOnDemand = true;

            //rootNode.NavigateUrl = function.Url;
            this.tvOrgTree.SelectedNode.ChildNodes.Add(rootNode);

        }



        #endregion

        #region 加载人员信息
        DataTable dtEmps = SysOrgDAL.GetSysPersInfosByDeptId(orgId);
        if (dtEmps == null) return;
        //获取根节点


        foreach (DataRow dr in dtEmps.Rows)
        {
            iPersCount += 1;
            PersCount.Value = Convert.ToString(iPersCount);
            rootNode = new TreeNode();
            rootNode.Value = dr["ID"].ToString();
            rootNode.Text = "<INPUT type='checkbox' id='PersCK' name='PersCK' value='" + dr["ID"].ToString() + "," + dr["Name"].ToString() + "'  onclick='ChoicePer(this);' >" + dr["Name"].ToString();
            rootNode.ImageUrl = "~/PayManage/XmlTree/icon/file2.gif";
            //rootNode.SelectAction = TreeNodeSelectAction;
            //rootNode.PopulateOnDemand = true;
            //EmpCom_Info_Main.aspx?PersID=219
            //rootNode.NavigateUrl = "../PayManage/EmpCom_File_Edit.aspx?ID=" + dr["ID"].ToString() + parmStr;
            this.tvOrgTree.SelectedNode.ChildNodes.Add(rootNode);
        }
        #endregion

        if (this.tvOrgTree.SelectedNode.ChildNodes.Count > 0)
            this.tvOrgTree.SelectedNode.Expand();
    }
    protected void tvOrgTree_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
    {
        e.Node.ImageUrl = "~/PayManage/XmlTree/icon/open.gif";
    }
    protected void tvOrgTree_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
    {
        e.Node.ImageUrl = "~/PayManage/XmlTree/icon/close.gif";
    }
}
